package com.jketing.entity.ams.work;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import com.jketing.annotation.FieldMeta;
import com.jketing.entity.BaseEntity;

/**
 * Repetition 重复
 * 
 * @author  李荣华
 * @version v1.0
 * @date     2018-10-11
 * @since   JPA 2.1
 */
@Entity
@Table(name = "Repetition_")
public class Repetition extends BaseEntity {
	/**
	 * 
	 */
	private static final long serialVersionUID = -9102503071889858425L;
	/**
	 * variety:所属品种
	 */
	@NotNull(message="所属品种不能为空")
	private Variety variety;
	/**
	 * spikeLength:穗长
	 */
	@FieldMeta(name="Float:spikeLength",explain="穗长")  
	private Float spikeLength = 0f;
	/**
	 * spikeLength:穗粗
	 */
	@FieldMeta(name="Float:spikeWide",explain="穗粗")  
	private Float spikeWide = 0f;
	/**
	 * spikeRowNumber:穗行数
	 */
	@FieldMeta(name="Short:spikeRowNumber",explain="穗行数")  
	private Short spikeRowNumber = 0 ;
	/**
	 * rowGrainNumber:行粒数
	 */
	@FieldMeta(name="Short:rowGrainNumber",explain="行粒数")  
	private Short rowGrainNumber = 0;
	/**
	 * grainColor:粒色
	 */
	@FieldMeta(name="String:grainColor",explain="粒色")  
	private String grainColor;
	/**
	 * grainType:粒型
	 */
	@FieldMeta(name="String:grainType",explain="粒型")  
	private String grainType;
	/**
	 * spikeType:穗型
	 */
	@FieldMeta(name="String:spikeType",explain="穗型")  
	private String spikeType;
	/**
	 * axialColour:轴色
	 */
	@FieldMeta(name="String:axialColour",explain="轴色")  
	private String axialColour;
	/**
	 * spikeRot:穗腐病
	 */
	@FieldMeta(name="Float:spikeRot",explain="穗腐病")  
	private Float spikeRot = 0f;
	/**
	 * grainRot:粒腐病
	 */
	@FieldMeta(name="Float:grainRot",explain="粒腐病")  
	private Float grainRot = 0f;
	/**
	 * alopeciaAcuity:秃尖度
	 */
	@FieldMeta(name="Float:alopeciaAcuity",explain="秃尖度")  
	private Float alopeciaAcuity = 0f;
	/**
	 * thousandGrainWeight:千粒重
	 */
	@FieldMeta(name="Float:thousandGrainWeight",explain="千粒重")  
	private Float thousandGrainWeight = 0f;
	/**
	 * freshPackageWeight:鲜包重
	 */
	@FieldMeta(name="Float:freshPackageWeight",explain="鲜包重")  
	private Float freshPackageWeight = 0f;
	/**
	 * dryPackageWeight:干包重
	 */
	@FieldMeta(name="Float:dryPackageWeight",explain="干包重")  
	private Float dryPackageWeight = 0f;
	/**
	 * dryGrainWeight:干粒重
	 */
	@FieldMeta(name="Float:dryGrainWeight",explain="干粒重")  
	private Float dryGrainWeight = 0f;
	/**
	 * seedRate:折籽率
	 */
	@FieldMeta(name="Float:seedRate",explain="折籽率")  
	private Float seedRate = 0f;
	/**
	 * seedYield:出籽率
	 */
	@FieldMeta(name="Float:seedYield",explain="出籽率")  
	private Float seedYield = 0f;
	/**
	 * plotFreshWeight:小区鲜重
	 */
	@FieldMeta(name="Float:plotFreshWeight",explain="小区鲜重")  
	private Float plotFreshWeight = 0f;
	/**
	 * plotYield:小区产量
	 */
	@FieldMeta(name="Float:plotYield",explain="小区产量")  
	private Float plotYield = 0f;
	/**
	 * yieldPerMu:折合亩产
	 */
	@FieldMeta(name="Float:yieldPerMu",explain="折合亩产")  
	private Float yieldPerMu = 0f;
	
	/**
	 * variety:所属品种
	 * 不能为空
	 */
	@ManyToOne
	@JoinColumn(name = "VarietyId")
	public Variety getVariety() {
		return variety;
	}
	public void setVariety(Variety variety) {
		this.variety = variety;
	}
	
	public Float getSpikeLength() {
		return spikeLength;
	}
	public void setSpikeLength(Float spikeLength) {
		this.spikeLength = spikeLength;
	}
	
	public Float getSpikeWide() {
		return spikeWide;
	}
	public void setSpikeWide(Float spikeWide) {
		this.spikeWide = spikeWide;
	}
	
	public Short getSpikeRowNumber() {
		return spikeRowNumber;
	}
	public void setSpikeRowNumber(Short spikeRowNumber) {
		this.spikeRowNumber = spikeRowNumber;
	}
	
	public Short getRowGrainNumber() {
		return rowGrainNumber;
	}
	public void setRowGrainNumber(Short rowGrainNumber) {
		this.rowGrainNumber = rowGrainNumber;
	}
	
	@Column(length=8)
	public String getGrainColor() {
		return grainColor;
	}
	public void setGrainColor(String grainColor) {
		this.grainColor = grainColor;
	}
	
	@Column(length=16)
	public String getGrainType() {
		return grainType;
	}
	public void setGrainType(String grainType) {
		this.grainType = grainType;
	}
	
	@Column(length=8)
	public String getSpikeType() {
		return spikeType;
	}
	public void setSpikeType(String spikeType) {
		this.spikeType = spikeType;
	}
	
	@Column(length=8)
	public String getAxialColour() {
		return axialColour;
	}
	public void setAxialColour(String axialColour) {
		this.axialColour = axialColour;
	}
	
	public Float getSpikeRot() {
		return spikeRot;
	}
	public void setSpikeRot(Float spikeRot) {
		this.spikeRot = spikeRot;
	}
	
	public Float getGrainRot() {
		return grainRot;
	}
	public void setGrainRot(Float grainRot) {
		this.grainRot = grainRot;
	}
	
	public Float getAlopeciaAcuity() {
		return alopeciaAcuity;
	}
	public void setAlopeciaAcuity(Float alopeciaAcuity) {
		this.alopeciaAcuity = alopeciaAcuity;
	}
	
	public Float getThousandGrainWeight() {
		return thousandGrainWeight;
	}
	public void setThousandGrainWeight(Float thousandGrainWeight) {
		this.thousandGrainWeight = thousandGrainWeight;
	}
	
	public Float getFreshPackageWeight() {
		return freshPackageWeight;
	}
	public void setFreshPackageWeight(Float freshPackageWeight) {
		this.freshPackageWeight = freshPackageWeight;
	}
	
	public Float getDryPackageWeight() {
		return dryPackageWeight;
	}
	public void setDryPackageWeight(Float dryPackageWeight) {
		this.dryPackageWeight = dryPackageWeight;
	}
	
	public Float getDryGrainWeight() {
		return dryGrainWeight;
	}
	public void setDryGrainWeight(Float dryGrainWeight) {
		this.dryGrainWeight = dryGrainWeight;
	}
	
	public Float getSeedRate() {
		return seedRate;
	}
	public void setSeedRate(Float seedRate) {
		if(seedRate==0){
			if(freshPackageWeight==0){
				this.seedRate = 0f;
			}else{
				this.seedRate = (dryGrainWeight/freshPackageWeight)*100;
				this.seedRate = (float)Math.round(this.seedRate*100)/100;//保留两位小数
			}
		}else{
			this.seedRate = seedRate;
		}
	}
	
	public Float getSeedYield() {
		return seedYield;
	}
	public void setSeedYield(Float seedYield) {
		if(seedYield==0){
			if(dryPackageWeight==0){
				this.seedYield = 0f;
			}else{
				this.seedYield = (dryGrainWeight/dryPackageWeight)*100;
				this.seedYield = (float)Math.round(this.seedYield*100)/100;//保留两位小数
			}
		}else{
			this.seedYield = seedYield;
		}
	}
	
	public Float getPlotFreshWeight() {
		return plotFreshWeight;
	}
	public void setPlotFreshWeight(Float plotFreshWeight) {
		this.plotFreshWeight = plotFreshWeight;
	}
	
	public Float getPlotYield() {
		return plotYield;
	}
	public void setPlotYield(Float plotYield) {
		if(plotYield==0){
			if(freshPackageWeight==0){
				this.plotYield = 0f;
			}else{
				this.plotYield = (dryGrainWeight/freshPackageWeight)*plotFreshWeight;
				this.plotYield = (float)Math.round(this.plotYield*100)/100;//保留两位小数
			}
		}else{
			this.plotYield = plotYield;
		}
	}
	
	public Float getYieldPerMu() {
		return yieldPerMu;
	}
	public void setYieldPerMu(Float yieldPerMu) {
		if(yieldPerMu==0){
			if(freshPackageWeight==0){
				this.yieldPerMu = 0f;
			}else{
				this.yieldPerMu =(((dryGrainWeight/freshPackageWeight)*plotFreshWeight)/20)*666.67f;
				this.yieldPerMu = (float)Math.round(this.yieldPerMu*100)/100;//保留两位小数
			}
		}else{
			this.yieldPerMu = yieldPerMu;
		}
	}
	
	/**
	 * 	equals 判断实例是否相等
	 * 
	 * 	是本类实例并且实例id值相等返回true
	 * 	其它情况返回false
	 * 
	 * 	@param object 其它实例
	 */
	@Override
	public boolean equals(Object object) {
		if (!(object instanceof Repetition)) {
			return false;
		}
		Repetition other = (Repetition) object;
		if(!id.equals(other.id)){
			return false;
		}
		return true;
	}
}
